import { defineStore } from 'pinia';

export const connectionAttr =  defineStore('connectionAttr', {
    state:()=>({
        connections:[],
        processDefinitionId:'',
    }),
    getters: {
        getProcessDefinitionId(): string {
          return this.processDefinitionId;
        },
       
      },
    actions:{
        setStateData(value){
            this.connections=value;
        },
        setProcessDefinitionId(processDefinitionId:string)
        {
            this.processDefinitionId = processDefinitionId;
        },
        addConnection(connection){
            this.connections.push(connection);
        },
        updateConnectionByNo(connectionNo,updatedProperties){
            const index = this.connections.findIndex(item => item.connectionNo === connectionNo);  
            if (index !== -1) {  
                Object.assign(this.connections[index], updatedProperties);  
            }
        },
        getConnectionByNo(connectionNo) {       
            //debugger;                 
            const index = this.connections.findIndex(item => item.connectionNo === connectionNo);  
            if (index !== -1) {  
               //return Promise.reject(this.connections[index]);
              return {hasVaule:true,connectioVaule:this.connections[index]}
            }
            else 
              return  {hasVaule:false,connectioVaule:null}
        },
        removeConnection(connectionNo){
            const index = this.connections.findIndex(item => item.connectionNo === connectionNo);  
            if (index !== -1) {  
                this.connections.splice(index,1);  
            }
        }
    }
});

 